﻿using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using QQ.Packet.Response;
using System.Collections.Generic;
using Tars.Net.Codecs;
using Tars.Net.Hosting;
using QQ.Client;

namespace QQ.Codecs
{
    public class RequestDecoder : MessageToMessageDecoder<SSOFrame>
    {
        public override bool IsSharable => true;
        private readonly IDecoder<IByteBuffer> decoder;
        HashSet<string> jcepacket = new HashSet<string>() { "ConfigPushSvc.PushReq" };
        private readonly ClientCallback clientCallback;

        public RequestDecoder(ClientCallback clientCallback, IDecoder<IByteBuffer> decoder)
        {
            this.decoder = decoder;
            this.clientCallback = clientCallback;
        }

        protected override void Decode(IChannelHandlerContext context, SSOFrame input, List<object> output)
        {
            if (jcepacket.Contains(input.commandName))
            {
                var tmp = decoder.DecodeRequest(input.plainBody);
                clientCallback.request_callback(tmp);
            }
        }
    }
}